﻿using Logic;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace web_CategoryMS.View.G02
{
    public partial class FS0203 : System.Web.UI.Page
    {
        FS0203Logic fS0203Logic = new FS0203Logic();

        #region 初始化事件
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        #endregion

        #region 检索方法
        private void Search()
        {
            DataTable dt = fS0203Logic.Search(txtOrderID.Text.Trim());
            if (dt != null && dt.Rows.Count > 0)
            {
                dgv.DataSource = dt;
                dgv.DataBind();
            }
            else
            {
                BindNullDT();
            }
        }
        #endregion

        #region 绑定空行
        private void BindNullDT()
        {
            DataTable dt = new DataTable();
            dt.Rows.Clear();
            dt.Columns.Add("iAutoID");
            dt.Columns.Add("vcProjectNo");
            dt.Columns.Add("vcOrderID");
            dt.Columns.Add("vcRequirementID");
            dt.Columns.Add("vcRequirementNo");
            dt.Columns.Add("vcRequirementName");
            dt.Columns.Add("vcRequirementDescription");
            dt.Columns.Add("vcRequirementContent");
            dt.Columns.Add("vcCreateID");
            DataRow dr = dt.NewRow();
            dr["iAutoID"] = "";
            dr["vcProjectNo"] = "";
            dr["vcOrderID"] = "";
            dr["vcRequirementID"] = "";
            dr["vcRequirementNo"] = "";
            dr["vcRequirementName"] = "";
            dr["vcRequirementDescription"] = "";
            dr["vcRequirementContent"] = "";
            dr["vcCreateID"] = "";
            dt.Rows.Add(dr);
            dgv.DataSource = dt;
            dgv.DataBind();
        }
        #endregion

        #region 行绑定事件
        protected void dgv_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    if (string.IsNullOrEmpty(e.Row.Cells[1].Text) || e.Row.Cells[1].Text == "&nbsp;")
                    {
                        return;
                    }
                    e.Row.Cells[6].Attributes.Add("onclick", "return OpenImage('" + e.Row.Cells[4].Text + "');");
                }
            }
            catch (Exception ex)
            {

            }
        }
        #endregion

        #region 检索事件
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                Search();
            }
            catch (Exception ex)
            {

            }
        }
        #endregion

        #region 添加备注信息
        protected void btnAddRemarks_Click(object sender, EventArgs e)
        {
            #region 获取选中的项
            List<string> Items = new List<string>();
            foreach (GridViewRow gvr in dgv.Rows)
            {
                if (((CheckBox)gvr.Cells[0].FindControl("ChkItem")).Checked)
                {
                    string iAutoID = gvr.Cells[1].Text;
                    if (!string.IsNullOrEmpty(iAutoID))
                    {
                        Items.Add(iAutoID);
                    }
                }
            }
            #endregion
            #region 弹出备注画面
            if (Items.Count > 0)
            {
                Session["FS0203SelectedList"] = Items;
                ScriptManager.RegisterStartupScript(this, typeof(Page), "", "openNew('FS0203_Sub.aspx?', '_blank', 'dialogWidth=150px;dialogHeight=160px;help=no;status=no;location=no;');", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, typeof(Page), "", "alert('至少选择一项！');", true);
            }
            #endregion

        }
        #endregion

        #region 保存回调方法
        protected void btnAddRemarks_Hid_Click(object sender, EventArgs e)
        {
            try
            {
                Search();
            }
            catch (Exception ex)
            {

            }
        }
        #endregion
    }
}
